18. Exercise: Pyramid Class

Pyramid

Exercise: Pyramid Class

  1. Create a class: Pyramid.
  2. Create 3 attributes: length, width, and height.
  3. Create a constructor to initialize all the attributes.
  4. Create accessor and mutator functions for all attributes.
  5. Think about the appropriate invariants and enforce them by throwing exceptions.
  6. Create a member function to calculate the volume of the pyramid.
  7. Optional: create a member function to calculate the surface area of the pyramid.

Volume

The volume of a pyramid is length * width * height / 3.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: jupyter
  • Opened files (when workspace is loaded): n/a